#include "CTimerm.h"


UINT Select(IN int _arry[], IN int _len) 
{
	CTimerm m;
	UINT count = 0;
	UINT index = 0;
	int i = 0;
	int j = 0;
	int tmp = 0;
	for (i = 0; i < _len - 1; i++)
	{
		index = i;
		for (j = i + 1; j < _len; j++)
		{
			index = _arry[index] > _arry[j] ? j : index;
			/*if (_arry[index] > _arry[j])
			{
				count++;
				index = j;
			}*/
		}
		tmp = _arry[i];
		_arry[i] = _arry[index];
		_arry[index] = tmp;
	}
	printf("%s count : %d\r\n",__FUNCTION__,count);
	return count;
}

UINT BubbleSortMethod(IN int _arry[], IN int _len)
{
	UINT count = 0;
	for (size_t i = 0; i < _len; i++)
	{
		for (size_t j = i; j < _len; j++)
		{
			if ((j + 1) < _len) 
			{
				if (_arry[j] > _arry[j + 1])
				{
					count++;
					int tmp = _arry[j + 1];
					_arry[j + 1] = _arry[j];
					_arry[j] = tmp;
				}
			}
		}
	}
	printf("%s count : %d\r\n", __FUNCTION__, count);
	return count;
}

UINT InsertionSort(IN int _arry[], IN int _len)
{
	UINT count = 0;
	for (size_t i = 1; i < _len - 1; i++)
	{
		for (size_t j = i; j > 0; j--)
		{
			if (_arry[j] < _arry[j - 1]) 
			{
				count++;
				int tmp = _arry[j];
				_arry[j] = _arry[j - 1];
				_arry[j - 1] = tmp;
			}
		}
	}
	return count;
}

int main() 
{

	int arry[30] = {2,-5,75,15,46,38,14,16,17,73,85,96,42,38,34,68,61,52,59,48,47,41,50,83,-62,-85,-3,-36,95,0};
	BubbleSortMethod(arry, 30);
	int arry2[30] = { 2,-5,75,15,46,38,14,16,17,73,85,96,42,38,34,68,61,52,59,48,47,41,50,83,-62,-85,-3,-36,95,0 };
	Select(arry2, 30);
	printf("befor : \r\n");
	for (size_t i = 0; i < 30; i++)
	{
		printf("%d ",arry[i]);
	}
	InsertionSort(arry, 30);
	printf("\r\nafter : \r\n");
	for (size_t i = 0; i < 30; i++)
	{
		printf("%d ", arry[i]);
	}

	return 0;
}